package sample.reflects.factory;

class Factory2 {
	public static fruit getInstance(String fuitName) {
		fruit f = null;
		try {
			f = (fruit) Class.forName(fuitName).newInstance();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}

		return f;

	}
}

public class Hello2ReflectFruit {
	public static void main(String[] args) {
		fruit f = Factory2.getInstance("sample.reflects.factory.Orange");
		if (f != null) {
			f.eat();
		}
	}

}
